1. /* slftancf.cpp by K.Tsuru */
  2. // function ID 4104 DRADIX
  3. /*********************************************
  4. SLong class
  5. It makes a table of tangent coefficients T[n]
  6. using the combination number combL().
  7. T[0] = 0, T[n] = Tn (n>0)
  8. **********************************************/
  9. #ifndef SN_H
  10. #include "sn.h"
  11. #endif
  12. static SNBlock<SLong>* T = NULL; //It keeps the result of calculation.
  13. static uint upto = 0; //How many terms have been calculated ? Tn(upto) ok
  14. void TanCoeffFree(){
  15. if(upto == 0) return;
  16. T->size(0,-1); T = NULL; upto = 0;
  17. }
  18. SLong TanCoeff(uint m){
  19. if(!upto){ //first call
  20. T = new SNBlock<SLong>(minArraySize);
  21. (*T)[0].SetSmall(1); upto = 1;
  22. }
  23. if(!m){ //free memory
  24. TanCoeffFree();
  25. return 0.0;
  26. } else if(m <= upto) return (*T)[m-1]; // T(m) = T[m-1] m-1 <= upto
  27. uint j, n;
  28. SLong sum, f;
  29. if(T->reserve(m) == 0) f.SetError(f.OUT_OF_RANGE,"TanCoeff", 4104);
  30. //cout << "m= " << m << " T->size() = " << T->size()<< endl;
  31. for(n = 1; n < m ; n++){
  32. sum.SetSmall((n & 1) ? -1 : 1);
  33. for(j = 1; j <= n ; j++){
  34. f = combL(2*n+1, 2*j)*(*T)[n-j];
  35. if(j & 1) sum += f;
  36. else sum -= f;
  37. }
  38. (*T)[n] = sum;
  39. }
  40. upto = m;
  41. return (*T)[m-1];
  42. }

slftancf.cpp : last modifiled at 2017/06/23 10:37:54(1,238 bytes)
created at 2017/10/07 10:26:49
The creation time of this html file is 2017/11/09 14:52:03 (Thu Nov 09 14:52:03 2017).